home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / ingres04.lzh / source / iutil / page.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-18  |  3.1 KB  |  186 lines

  1. # include    <ingres.h>
  2. # include    <access.h>
  3. # include    <aux.h>
  4. # include    <lock.h>
  5.  
  6. /*
  7. **    UNIX read/write counters
  8. */
  9.  
  10. long    Accuread, Accuwrite;
  11. long    Accusread;
  12.  
  13. /*
  14. **    GETPAGE - get the page on which tid is found
  15. **
  16. **
  17. **    Parameters:
  18. **        d - descriptor for relation
  19. **        tid - tid which specifies the page
  20. **
  21. **    Return Codes:
  22. **        0 - success        
  23. **        -1, -2 - AMREAD_ERR, AMWRITE_ERR        
  24. **
  25. **    Trace Flags:
  26. **        26.9, 26.10
  27. **
  28. **    Called by:
  29. **        fill_rel(), add_ovflo(), bndxsearch(), delete(),
  30. **        get(), getequal(), ndxsearch(), noclose(), replace()
  31. **        scan_dups()
  32. **
  33. */
  34. get_page(d, tid)
  35. register DESC    *d;
  36. TID        *tid;
  37. {
  38.     register int        i;
  39.     long            pageid;
  40.     register struct accbuf    *b;
  41.     struct accbuf        *b1;
  42.     int            lk;        /* lock condition*/
  43.     extern struct accbuf    *choose_buf();
  44.     extern long        lseek();
  45.  
  46. #    ifdef xATR3
  47.     if (tTf(26, 9))
  48.     {
  49.         printf("GET_PAGE: %.14s,", d->reldum.relid);
  50.         dumptid(tid);
  51.     }
  52. #    endif
  53.  
  54.     pluck_page(tid, &pageid);
  55.     if ((b = choose_buf(d, pageid)) == NULL)
  56.         return (-1);
  57.     top_acc(b);
  58.     lk = Acclock && (d->reldum.relstat & S_CONCUR) && (d->relopn < 0);
  59.     if ((b->thispage != pageid) || (lk && !(b->bufstatus & BUF_LOCKED)))
  60.     {
  61.         if (i = pageflush(b))
  62.             return (i);
  63. #        ifdef xATR1
  64.         if (tTf(26, 10))
  65.         {
  66.             printf("GET_PAGE: rdg pg %ld", pageid);
  67.             printf(",relid ");
  68.             dumptid((TID *) &d->reltid);
  69.         }
  70. #        endif
  71.         b->thispage = pageid;
  72.         if (lk)
  73.         {
  74.             b1 = Acc_head;
  75.             for (; b1 != 0; b1 = b1->modf)
  76.                 if (b1->bufstatus & BUF_LOCKED)
  77.                     pageflush(b1);  /*  */
  78.             if (setpgl(b) < 0)
  79.                 syserr("get-page: lk err");
  80.         }
  81.         if ((lseek(d->relfp, (long)(pageid * PGSIZE), 0) == -1) ||
  82.             (read(d->relfp, (char *) b, PGSIZE) != PGSIZE))
  83.         {
  84.             resetacc(b);
  85.             return (acc_err(AMREAD_ERR));
  86.         }
  87.         Accuread++;
  88.         if (d->reldum.relstat & S_CATALOG)
  89.         {
  90.             Accusread++;
  91.         }
  92.     }
  93.     return (0);
  94. }
  95.  
  96. /*
  97. **    PAGEFLUSH - flush the buffered page to disk
  98. **
  99. **    Parameters:
  100. **        buf - the buffer
  101. **
  102. **    Return Codes:
  103. **        0 -- successful
  104. **        AMWRITE_ERR - error in writing
  105. **
  106. **    Trace Flags:
  107. **        29.2, 29.3
  108. **
  109. */
  110. pageflush(buf)
  111. struct accbuf    *buf;
  112. {
  113.     register struct accbuf    *b;
  114.     register int        allbufs;
  115.     int            err;
  116.  
  117.     b = buf;
  118. #    ifdef xATR3
  119.     if (tTf(29, 2))
  120.     {
  121.         printf("PAGEFLUSH: %x=", b);
  122.         if (b != NULL)
  123.             dumptid(&b->rel_tupid);
  124.         else
  125.             printf("all\n");
  126.     }
  127. #    endif
  128.     err = FALSE;
  129.     allbufs = FALSE;
  130.     if (b == 0)
  131.     {
  132.         b = Acc_buf;
  133.         allbufs = TRUE;
  134.     }
  135.  
  136.     do
  137.     {
  138.         if (b->bufstatus & BUF_DIRTY)
  139.         {
  140. #            ifdef xATR1
  141.             if (tTf(29, 3))
  142.             {
  143.                 printf("PAGEFLUSH: wr pg %ld", b->thispage);
  144.                 printf(",stat %d,relid ", b->bufstatus);
  145.                 dumptid((TID *) &b->rel_tupid);
  146.             }
  147. #            endif
  148.  
  149.  
  150.             b->bufstatus &= ~BUF_DIRTY;
  151.             if ((lseek(b->filedesc, (long)(b->thispage * PGSIZE), 0)== -1) ||
  152.                 (write(b->filedesc, (char *) b, PGSIZE) != PGSIZE))
  153.             {
  154.                 resetacc(b);
  155.                 err = TRUE;
  156.             }
  157.             Accuwrite++;
  158.  
  159.         }
  160.         if (Acclock && b->bufstatus & BUF_LOCKED)
  161.             unlpg(b);
  162.  
  163.     } while (allbufs && (b = b->modf) != NULL);
  164.  
  165.     if (err)
  166.         return (acc_err(AMWRITE_ERR));
  167.  
  168.     return (0);
  169. }
  170. /*
  171. **  ACC_ERR -- set global error indicator "Accerror"
  172. **
  173. **    Trace Flags:
  174. **        20.4-5
  175. */
  176.  
  177. acc_err(errnum)
  178. int    errnum;
  179. {
  180.     Accerror = errnum;
  181. #    ifdef xATR1
  182.     tTfp(20, 4, "ACC_ERR: %d\n", Accerror);
  183. #    endif
  184.     return (Accerror);
  185. }
  186.